#ifndef __INCLUDED_UUT_IPC_H_
#define __INCLUDED_UUT_IPC_H_

#include "UUTDef.h"

UUT_START

class IIPCService;
class IIPCClient;
class IIPCSink;

void InitIPCService();
void TermIPCService();
IIPCService* GetIPCService();

typedef UUTUInt32 IPCChannel;
#define INVALID_IPC_CHANNEL 0
typedef enum
{
	IPCResult_OK = 0,
	IPCResult_Unknown_Error = 1,
	IPCResult_NULL_Pointer = 2,
	IPCResult_Internel_Error = 3,
	IPCResult_No_Such_Channel = 4,
	IPCResult_No_Implementation
}IPCResult;

class IIPCClient
{
public:
	/************************************************************************/
	/*  if callback is null, we'll remove the original callback
		if callback is not null, the old callback will be replaced
		callback is not owned by IIPCClient
		if success return: IPCResult_OK
	*/
	/************************************************************************/
	virtual IPCResult SetCallBack(IIPCSink* callback) = 0;

	/************************************************************************/
	/*	if channel doesn't exist, return: IPCResult_No_Such_Channel
		if data is null or size is 0, return: IPCResult_NULL_Pointer
		this API will send the data in a synchronized way
		after API called, the value "sent" will be set as the sent count
		if API success, return: IPCResult_OK
	*/
	/************************************************************************/
	virtual IPCResult SendData(IPCChannel channel, const UUTByte* data, const UUTUInt32 size, UUTUInt32& sent) = 0;

	/************************************************************************/
	/* if channel doesn't exist, return: IPCResult_No_Such_Channel
		if data is null or size is 0, return: IPCResult_NULL_Pointer
		this API will send the data in a asynchronized way
		if API success, return: IPCResult_OK
	*/
	/************************************************************************/
	virtual IPCResult AsyncSendData(IPCChannel channel, const UUTByte* data, const UUTUInt32 size) = 0;
};

class IIPCService
{
public:
	// return the unique client instance for myself, this API can only be called for one time
	// if the client called it for more than one time, the behavior is undefined. (return NULL!)
	virtual IIPCClient* GetClient(const UUTTString& name) = 0;

	// loop the channel for specified channel name
	virtual IPCResult FindChannel(const UUTTString& name, IPCChannel& channel) = 0;
};

class IIPCSink
{
public:
	virtual IPCResult ReceiveSyncData(const IPCChannel src, const UUTByte* data, const UUTUInt32 size) = 0;
	virtual IPCResult ReceiveAsyncData(const IPCChannel src, const UUTByte* data, const UUTUInt32 size) = 0;
};

UUT_END

#endif //__INCLUDED_UUT_IPC_H_
